
#ifndef TIMER_HPP
#define TIMER_HPP

#include <functional>
using namespace std;

namespace zhb
{
    class Timer
    {
    public:
        using TimerCallback = std::function<void()>;

    private:
        int m_timerId;
        TimerCallback m_callback;
        int tag;                        // 1 one  2  inter
        bool settimer(size_t interval); // 设置时间间隔

    public:
        Timer();
        ~Timer();
        Timer(const Timer &) = delete;
        Timer &operator=(const Timer &) = delete;

        Timer(Timer&&it):
        m_timerId(it.m_timerId),
        m_callback(it.m_callback)
        {
            m_timerId=-1;
            m_callback=nullptr;
        }
        Timer&operator=(Timer&&it){
            if(this!=&it){
                m_timerId=it.m_timerId;
                m_callback=it.m_callback;
                it.m_timerId=-1;
                it.m_callback=nullptr;
            }
            return *this;
        }

        bool init();
        bool set_timer(const TimerCallback &cb, size_t interval);
        bool resete_timer(size_t interval); // 重置定时时间
        void handle_event();                // 时间到达调用此函数，此函数在调用回调函数
        size_t get_TimerId() const;
        bool close_timer();
    };
}

#endif